﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>小苹果系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>

    <style>
        html, body {
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="layui-form" lay-filter="layuiadmin-form-emps" id="layuiadmin-form-emps" style="padding: 5px;">
            <div class="layui-card" style="height: 100%;padding:5px">
                <div class="layui-form-item">
                    <label class="layui-form-label">当前密码</label>
                    <div class="layui-input-inline">
                        <input type="password" oninput="if(this.value==''){this.type='text'}else(this.type='password')" name="curpass" id="curpass" value="" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-inline">
                        <input type="text" oninput="if(this.value==''){this.type='text'}else(this.type='password')" name="pass" id="LAY_password" lay-verify="pass" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认新密码</label>
                    <div class="layui-input-inline">
                        <input type="text" oninput="if(this.value==''){this.type='text'}else(this.type='password')" id="repass" name="repass" lay-verify="repass" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="setmypass">确认修改</button>
                    </div>
                </div>
            </div>
        </div>
</body>
</html>

<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element'], {
        data: {
            $layui: null,
            right: null,
        },
        pageload: function (right) {
            this.data.right = right;
            this.initevent();
        },
        //初始化事件
        initevent: function () {
            var self = this;
            var layer = this.data.$layui.layer;
            var form = this.data.$layui.form;
            var element = this.data.$layui.element;

            //自定义验证规则
            form.verify({
                //密码验证
                pass: [
                    /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/
                    , '必须包含大小写字母和数字的组合，可以使用特殊字符，长度大于8'
                ],
                //确认密码
                repass: function (value) {
                    if (value !== $('#LAY_password').val()) {
                        return '两次密码输入不一致';
                    }
                }
            });

            //修改我的密码
            form.on('submit(setmypass)', function (data) {
                self.UpdateMyPass(data);
            });
        },
        
        UpdateMyPass: function (data) {
            var self = this;
            var layer = this.data.$layui.layer;
            var form = this.data.$layui.form;

            var field = data.field; //获取提交的字段
            var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });

            lobsterlayui.POST("/admin/v1/usersetup/UpdateMyPass", { "userid": self.data.right.SSOUserId, "curpass": field.curpass, "pass": field.pass }).then(data => {
                layer.close(load);
                layer.msg("修改密码成功", { time: 1 * 1000 }, function () {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭弹层
                })
            }).catch(res => {
                layer.close(load);
                layer.msg(res.msg);
            });

            return false;
        }
    });


</script>